package com.itheima.dubbo.mysql.mapper;

import com.itheima.commons.model.domain.AgeDistribution;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

public interface AgeDistributionMapper {
    /**
     * 统计年龄分布
     * @return
     */
    @Select("SELECT age as title,COUNT(*) as amount FROM \n" +
            "(select case  when age>20 and age<=30 then '20-30' when age>30 and age<=40 then '30-40' when age<=20 then '0-20' when age>40 THEN '40+' end as age from tb_user_info WHERE created>#{startTime} and  created<#{endTime}\n" +
            ") as a GROUP BY age")
    List<AgeDistribution> query(@Param("startTime") String startTime,@Param("endTime") String endTime);
}
